% % ======================================================================== % Titelseite % ---------- % \begin{titlepage} \mbox{~} \bigskip \mbox{~} \bigskip \begin{center} \Huge {\bf PASCAL--XSC} \\[2ex] \LARGE {\bf A short introduction} \\ {\bf to the new language} \\ \bigskip \mbox{~} \\ \bigskip \normalsize \vspace{7cm} Numerik Software GmbH \\ Rettigstr. 6 \\ W-7570 Baden-Baden \\ Federal Republic of Germany \\ Tel: +49 (721) 370913 \\ Fax: +49 (721) 370928 \\ email: ae18@dkauni2.bitnet \\ \end{center} \end{titlepage} % \newpage \begin{titlepage} \mbox{} \end{titlepage} \newpage % % ======================================================================== % Titel % ----- % \thispagestyle{empty} \begin{center} \LARGE {\bf PASCAL--XSC} \\ {\bf A short introduction} \\ {\bf to the new language} \\ \bigskip \end{center} % % ======================================================================== % Seitenueberschriften % -------------------- % \markboth{M. Neaga and D. Ratz}{PASCAL--XSC --- New Concepts % for Scientific Computation} % % ======================================================================== % Kurzzusammenfassung % ------------------- \begin{abstract} The new programming language PASCAL--XSC is presented with an emphasis on the new concepts for scientific computation and numerical data processing of the PASCAL--XSC compiler. PASCAL--XSC is a universal PASCAL extension with extensive standard modules for scientific computation. It is available for personal computers, workstations, mainframes and supercomputers by means of an implementation in C. By using the mathematical modules of PASCAL--XSC, numerical algorithms which deliver highly accurate and automatically verified results can be programmed in an easy manner. PASCAL--XSC simplifies the design of programs in engineering scientific computation by modular program structure, user-defined operators, overloading of functions, procedures, and operators, functions and operators with arbitrary result type, dynamic arrays, arithmetic standard modules for additional numerical data types with operators of highest accuracy, standard functions of high accuracy and exact evaluation of expressions. The most important advantage of the new language is that programs written in PASCAL--XSC are easily readable. This is due to the fact that all operations, even those in the higher mathematical spaces, have been realized as operators and can be used in conventional mathematical notation. In addition to PASCAL--XSC a large number of numerical problem-solving routines with au\-to\-ma\-tic result ve\-ri\-fi\-ca\-tion are available. The language supports the development of such routines. \end{abstract} % % ======================================================================== % Text des Vortrages % ------------------ \section{Introduction} % These days, the elementary arithmetic operations of electronic com\-puters are usually approximated by floating-point operations of highest accuracy. In particular, this means that for any choice of operands, the computed result coincides with the rounded exact result of the operation. See the IEEE Arithmetic Standard \cite{psc10} as an example. This arithmetical standard also requires the four basic arithmetic operations $+,-,*,$ and $/$ with directed roundings. A large number of processors already on the market provide these operations. So far, however, no common programming language allows access to them. On the other hand, there has been a noticeable shift in scientific computation from general purpose computers to vector and parallel computers. These so-called super-computers provide additional arithmetic operations such as ``multiply and add'' and ``accumulate'' or ``multiply and accumulate'' (see \cite{psc11}). These hardware operations should always deliver a result of highest accuracy, but as of yet, no processor which fulfills this requirement is available. In some cases, the results of numerical algorithms computed on vector computers are totally different from the results computed on a scalar processor (see \cite{hammer},\cite{ratz}). Continuous efforts have been made to enhance the power of programming languages. New powerful languages such as ADA have been designed, and enhancement of existing languages such as FORTRAN is in constant progress. However, since these languages still lack a precise definition of their arithmetic, the same program may produce different results on different processors. PASCAL--XSC is the result of a long-term venture by a team of scientists to produce a powerful tool for solving scientific problems. The math\-emat\-ical definition of the arithmetic is an intrinsic part of the language including optimal arithmetic operations with directed roundings which are directly accessable in the language. Further arithmetic operations for intervals and complex numbers and even vector/matrix operations provided by precompiled arithmetical modules are defined with maximum accuracy according to the rules of semimorphism (see \cite{psc5}). % \section{The Language PASCAL--XSC} % PASCAL--XSC is an e{\underline X}tension of the programming language PASCAL for {\underline S}cientific {\underline C}omputation. A first approach to such an extension (PASCAL--SC) has been available since 1980. The specification of the extensions has been continuously improved in recent years by means of essential language concepts, and the new langauge PASCAL--XSC \cite{pxscbuch},\cite{pxscbook} was developed. It is now available for personal computers, workstations, mainframes, and supercomputers by means of an implementation in C. PASCAL--XSC contains the following features: % \begin{itemize} \itemsep0em \item Standard PASCAL \item Universal operator concept (user-defined operators) \item Functions and Operators with arbitrary result type \item Overloading of procedures, functions and operators \item Module concept \item Dynamic arrays \item Access to subarrays \item String concept \item Controlled rounding \item Optimal (exact) scalar product \item Standard type {\sl dotprecision\/} (a fixed point format to cover the whole range of floating-point products) \item Additional arithmetic standard types such as {\sl complex, interval, rvector}, \mbox{\sl rmatrix\/} etc. \item Highly accurate arithmetic for all standard types \item Highly accurate standard functions \item Exact evaluation of expressions (\#-expressions) \end{itemize} % The new language features, developed as an extension of PASCAL, will be discussed in the following sections. % % Neues Kapitel % \subsection{Standard Data Types, Predefined Operators, and Functions} % In addition to the data types of standard PASCAL, the following nu\-meri\-cal data types are available in PASCAL--XSC: \begin{quote} \begin{tabular}{llll} {\sl interval} & {\sl complex} & {\sl cinterval} & \\ {\sl rvector} & {\sl cvector} & {\sl ivector} & {\sl civector}\\ {\sl rmatrix} & {\sl cmatrix} & {\sl imatrix} & {\sl cimatrix} \end{tabular} \end{quote} where the prefix letters {\sl r, i,} and {\sl c\/} are abbreviations for {\sl \underline real, \underline interval\/}, and {\sl \underline complex\/}. So {\sl cinterval\/} means {\sl complex interval\/} and, for example, {\sl cimatrix\,} denotes complex interval matrices, whereas {\sl rvector\,} specifies real vectors. The vector and matrix types are defined as dynamic arrays and can be used with arbitrary index ranges. A large number of operators are predefined for theses types in the arithmetic modules of PASCAL--XSC (see section \ref{sec:psc8}). All of these operators deliver results with maximum accuracy. In table 1 the 29 predefined standard operators of PASCAL--XSC are listed according to priority. % % Tabelle mit den Standardoperatoren % ================================== % \begin{center} \small % \begin{tabular}{|c||c|l|} \hline %---------------------------------------------------------------------- Type \rule[-2ex]{0ex}{5ex} & Priority & \multicolumn{1}{c|}{Operators} \\ % \hline \hline %--------------------------------------------- %--------------------------------------------- monadic \rule{0ex}{3ex} & 3 & monadic $+$, monadic $-$, {\bf not} \\ %--------------------------------------------- & (highest) & \\[2ex] %--------------------------------------------- multiplicative & 2 & {\bf and}, {\bf div}, {\bf mod} \\ %--------------------------------------------- & & $ *, \tdown, \tup, / ,\ddown, \dup, ** $ \\[2ex] %--------------------------------------------- additive & 1 & {\bf or} \\ %--------------------------------------------- & & $ +, \pdown, \pup, -, \mdown, \mup, +* $ \\[2ex] %--------------------------------------------- relational & 0 & {\bf in} \\ %--------------------------------------------- & (lowest) & $ =, <>, <=, <, >=, >, >< $ \\[1.5ex] %--------------------------------------------- \hline \end{tabular}\\[1.5ex] % {\normalsize Table 1:~ Precedence of the Built-in Operators} \end{center} % =============================================== % \pagebreak \noindent Compared to standard PASCAL, there are 11 new operator symbols. These are the operators $\circ \!\! <$ and $\circ \!\! >, \: \circ \in \{+,-,*, /\}$ for operations with downwardly and also upwardly directed rounding and the operators $**,+*,><$ needed in interval computations for the intersection, the convex hull, and the disconnectivity test. Tables 2 and 3 show all predefined arithmetic and relational operators in connection with the possible combinations of operand types. \vfill \begin{center} \small \setlength{\arraycolsep}{2pt} \setlength{\tabcolsep}{2pt} % \begin{tabular}{|c||c|c|c|c|c|c|} \hline %---------------------------------------------------------------------- \begin{tabular}{c} \setlength{\unitlength}{1.0em} \begin{picture}(6,4) \put(-0.5,4){\line(3,-2){6.50}} \put(0,2){\makebox(0,0)[tl]{\scriptsize left}} \put(0,1){\makebox(0,0)[tl]{\scriptsize operand}} \put(6,3){\makebox(0,0)[br]{\scriptsize right}} \put(6,2){\makebox(0,0)[br]{\scriptsize operand}} \end{picture} \end{tabular} % & \begin{tabular}{c} integer \\ real \\ complex \end{tabular} & \begin{tabular}{c} interval \\ cinterval \end{tabular} & \begin{tabular}{c} rvector \\ cvector \end{tabular} & \begin{tabular}{c} ivector \\ civector \end{tabular} & \begin{tabular}{c} rmatrix \\ cmatrix \end{tabular} & \begin{tabular}{c} imatrix \\ cimatrix \end{tabular} \\ % \hline \hline %--------------------------------------------------------------------- %--------------------------------------------------------------------- \begin{tabular}{l} $\mbox{\em monadic}^{^1)}$ \end{tabular} & \rule[-2.5ex]{0ex}{5.5ex} $ +,- $ & $ +,- $ & $ +,- $ & $ +,- $ & $ +,- $ & $ +,- $ \\ % \hline %--------------------------------------------------------------------- \rule[-4.0ex]{0ex}{8.5ex} \begin{tabular}{c} integer \\ real \\ complex \end{tabular} & $ \begin{array}{c} \hfill \mbox{}^2) \\[-1.5ex] \circ,\circ \! <,\circ \! >, \:\: \\ +* \\ \end{array} $ & $ \begin{array}{c} +,-,*,/, \\ +* \\ \end{array} $ & $ *,* \! <,* \! > $ & $ * $ & $ *,* \! <,* \! > $ & $ * $ \\ % \hline %--------------------------------------------------------------------- \rule[-3.0ex]{0ex}{7.5ex} \begin{tabular}{c} interval \\ cinterval \end{tabular} & $ \begin{array}{c} +,-,*,/, \\ +* \\ \end{array} $ & $ \begin{array}{c} +,-,*,/, \\ +*,** \\ \end{array} $ & $ * $ & $ * $ & $ * $ & $ * $ \\ % \hline %--------------------------------------------------------------------- \rule[-4.0ex]{0ex}{8.5ex} \begin{tabular}{c} rvector \\ cvector \end{tabular} & $ \begin{array}{c} *,* \! <,* \! >, \\ /,/ \! <,/ \! > \end{array} $ & $ *,/ $ & $ \begin{array}{c} \hfill \mbox{}^3) \\[-1.5ex] \circ,\circ \! <,\circ \! >, \:\: \\ +* \\[0.5ex] \end{array} $ & $ \begin{array}{c} \hfill \mbox{}^4) \\[-1.5ex] +,-,*, \:\: \\ +* \\[0.25ex] \end{array} $ & & \\ % \hline %--------------------------------------------------------------------- \rule[-3.25ex]{0ex}{8.5ex} \begin{tabular}{c} ivector \\ civector \end{tabular} & $ *,/ $ & $ *,/ $ & $ \begin{array}{c} \hfill \mbox{}^4) \\[-1.5ex] +,-,*, \:\: \\ +* \\[0.25ex] \end{array} $ & $ \begin{array}{c} \hfill \mbox{}^4) \\[-1.5ex] +,-,*, \:\: \\ +*,** \\[0.25ex] \end{array} $ & & \\ % \hline %--------------------------------------------------------------------- \rule[-4.0ex]{0ex}{8.5ex} \begin{tabular}{c} rmatrix \\ cmatrix \end{tabular} & $ \begin{array}{c} *,* \! <,* \! >, \\ /,/ \! <,/ \! > \end{array} $ & $ *,/ $ & $ *,* \! <,* \! > $ & $ * $ & $ \begin{array}{c} \hfill \mbox{}^3) \\[-1.5ex] \circ,\circ \! <,\circ \! >, \:\: \\ +* \\[0.5ex] \end{array} $ & $ \begin{array}{c} \hfill \mbox{}^4) \\[-1.5ex] +,-,*, \:\: \\ +* \\[0.25ex] \end{array} $ \\ % \hline %--------------------------------------------------------------------- \rule[-3.25ex]{0ex}{8.5ex} \begin{tabular}{c} imatrix \\ cimatrix \end{tabular} & $ *,/ $ & $ *,/ $ & $ * $ & $ * $ & $ \begin{array}{c} \hfill \mbox{}^4) \\[-1.5ex] +,-,*, \:\: \\ +* \\[0.25ex] \end{array} $ & $ \begin{array}{c} \hfill \mbox{}^4) \\[-1.5ex] +,-,*, \:\: \\ +*,** \\[0.25ex] \end{array} $ \\ % \hline %--------------------------------------------------------------------- \multicolumn{7}{c}{}\\ \multicolumn{7}{l} {\footnotesize \begin{tabular}{l} \mbox{} \\ $\mbox{}^1)$ The operators of this row are monadic (\ie there is no left operand). \\[1.5ex] $\mbox{}^2)$ $ \circ \in \{ +,-,*,/ \} $ \\[1.5ex] $\mbox{}^3)$ $ \circ \in \{ +,-,* \}$, where $*$ denotes the scalar or matrix product.\\[1.5ex] $\mbox{}^4)$ $*$ denotes the scalar or matrix product. \\[3.0ex] $+*$ : Interval hull \\[1.5ex] $** \;$ : Interval intersection \end{tabular} } % \end{tabular}\\[1.5ex] % {\normalsize Table 2:~ Predefined Arithmetical Operators} \end{center} % %============================================================================= % \clearpage \noindent Compared with standard PASCAL, PASCAL--XSC provides an extended set of mathematical standard functions (see table 4). These functions are available for the types {\sl real}, {\sl complex}, {\sl interval\/}, and {\sl cinterval} with a generic name and deliver a result of maximum accuracy. The functions for the types {\sl complex, interval\/}, and {\sl cinterval\/} are provided in the arithmetic modules of PASCAL--XSC. \vfill \begin{center} \small \setlength{\arraycolsep}{2pt} \setlength{\tabcolsep}{2pt} % \begin{tabular}{|c||c|c|c|c|c|c|} \hline %---------------------------------------------------------------------- \begin{tabular}{c} \setlength{\unitlength}{1.0em} \begin{picture}(6,4) \put(-0.5,4){\line(3,-2){6.50}} \put(0,2){\makebox(0,0)[tl]{\scriptsize left}} \put(0,1){\makebox(0,0)[tl]{\scriptsize operand}} \put(6,3){\makebox(0,0)[br]{\scriptsize right}} \put(6,2){\makebox(0,0)[br]{\scriptsize operand}} \end{picture} \end{tabular} % & \begin{tabular}{c} integer \\ real \\ complex \end{tabular} & \begin{tabular}{c} interval \\ cinterval \end{tabular} & \begin{tabular}{c} rvector \\ cvector \end{tabular} & \begin{tabular}{c} ivector \\ civector \end{tabular} & \begin{tabular}{c} rmatrix \\ cmatrix \end{tabular} & \begin{tabular}{c} imatrix \\ cimatrix \end{tabular} \\ % \hline \hline %--------------------------------------------------------------------- %--------------------------------------------------------------------- \begin{tabular}{c} integer \\ real \\ complex \end{tabular} \rule[-4ex]{0ex}{8ex} & $ \begin{array}{c} =,<>, \\ <=,<, \\ >=,> \end{array} $ & $ \begin{array}{c} \mbox{\bf in} \\ =,<> \end{array} $ & & & & \\ % \hline %--------------------------------------------------------------------- \begin{tabular}{c} interval \\ cinterval \end{tabular} \rule[-6ex]{0ex}{13ex} & $ =,<> $ & $ \begin{array}{c} ~~~~~~~~~~\mbox{}^1) \\[-1.5ex] \mbox{\bf in}, ><, \\ =,<>, \\ <=,<, \\ >=,> \\ \end{array} $ & & & & \\ % \hline %--------------------------------------------------------------------- \begin{tabular}{c} rvector \\ cvector \end{tabular} \rule[-3ex]{0ex}{8ex} & & & $ \begin{array}{c} =,<>, \\ <=,<, \\ >=,> \end{array} $ & $ \begin{array}{c} \mbox{\bf in} \\ =,<> \end{array} $ & & \\ % \hline %--------------------------------------------------------------------- \begin{tabular}{c} ivector \\ civector \end{tabular} \rule[-6ex]{0ex}{13ex} & & & $ =,<> $ & $ \begin{array}{c} ~~~~~~~~~~\mbox{}^1) \\[-1.5ex] \mbox{\bf in}, ><, \\ =,<>, \\ <=,<, \\ >=,> \\ \end{array} $ & & \\ % \hline %--------------------------------------------------------------------- \begin{tabular}{c} rmatrix \\ cmatrix \end{tabular} \rule[-3ex]{0ex}{8ex} & & & & & $ \begin{array}{c} =,<>, \\ <=,<, \\ >=,> \end{array} $ & $ \begin{array}{c} \mbox{\bf in} \\ =,<> \end{array} $ \\ % \hline %--------------------------------------------------------------------- \begin{tabular}{c} imatrix \\ cimatrix \end{tabular} \rule[-6ex]{0ex}{13ex} & & & & & $ =,<> $ & $ \begin{array}{c} ~~~~~~~~~~\mbox{}^1) \\[-1.5ex] \mbox{\bf in}, ><, \\ =,<>, \\ <=,<, \\ >=,> \\ \end{array} $ \\ % \hline %--------------------------------------------------------------------- \multicolumn{7}{c}{}\\ \multicolumn{7}{l} {\footnotesize \begin{tabular}{l} \mbox{} \\ $\mbox{}^1)$ The operators $<=$ and $<$ denote the ``subset'' relations,\\ ~~~\,{}$>=$ and $>$ denote the ``superset'' relations.\\[2ex] $ \vee \in \{ \mbox{=, $<$$>$, $<$, $<$=, $>$, $>$=} \}$\\[1.5ex] $><$ : Test on disjointedness for intervals \\[1.5ex] {\bf in}\quad : \begin{tabular}{l} Test on membership of a point in an interval or test on\\ strict inclusion of an interval in the interior of an interval \end{tabular} \end{tabular}} % \end{tabular}\\[1.5ex] % {\normalsize Table 3:~ Predefined Relational Operators} \end{center} % \clearpage % % % % Tabelle mit den Standardfunktionen % ================================== % \begin{center} \begin{tabular}{|r||l|l|c|} \hline %---------------------------------------------------------------------- \rule[-1.5ex]{0ex}{4ex} & \multicolumn{1}{c|}{Function} & \multicolumn{1}{c|}{Generic Name} & Argument Type \\ % \hline \hline %--------------------------------------------- %--------------------------------------------- 1 \rule[-1.5ex]{0ex}{4ex} & Absolute Value & ~~~~~~~abs & {\large $*$} \\ \hline %--------------------------------------------- 2 \rule[-1.5ex]{0ex}{4ex} & Arc Cosine & ~~~~~~~arccos & {\large $*$} \\ \hline %--------------------------------------------- 3 \rule[-1.5ex]{0ex}{4ex} & Arc Cotangent & ~~~~~~~arccot & {\large $*$} \\ \hline %--------------------------------------------- 4 \rule[-1.5ex]{0ex}{4ex} & Inverse Hyperbolic Cosine & ~~~~~~~arcosh & {\large $*$} \\ \hline %--------------------------------------------- 5 \rule[-1.5ex]{0ex}{4ex} & Inverse Hyperbolic Cotangent & ~~~~~~~arcoth & {\large $*$} \\ \hline %--------------------------------------------- 6 \rule[-1.5ex]{0ex}{4ex} & Arc Sine & ~~~~~~~arcsin & {\large $*$} \\ \hline %--------------------------------------------- 7 \rule[-1.5ex]{0ex}{4ex} & Arc Tangent & ~~~~~~~arctan & {\large $*$} \\ \hline %--------------------------------------------- 8 \rule[-1.5ex]{0ex}{4ex} & Inverse Hyperbolic Sine & ~~~~~~~arsinh & {\large $*$} \\ \hline %--------------------------------------------- 9 \rule[-1.5ex]{0ex}{4ex} & Inverse Hyperbolic Tangent & ~~~~~~~artanh & {\large $*$} \\ \hline %--------------------------------------------- 10 \rule[-1.5ex]{0ex}{4ex} & Cosine & ~~~~~~~cos & {\large $*$} \\ \hline %--------------------------------------------- 11 \rule[-1.5ex]{0ex}{4ex} & Cotangent & ~~~~~~~cot & {\large $*$} \\ \hline %--------------------------------------------- 12 \rule[-1.5ex]{0ex}{4ex} & Hyperbolic Cosine & ~~~~~~~cosh & {\large $*$} \\ \hline %--------------------------------------------- 13 \rule[-1.5ex]{0ex}{4ex} & Hyperbolic Cotangent & ~~~~~~~coth & {\large $*$} \\ \hline %--------------------------------------------- 14 \rule[-1.5ex]{0ex}{4ex} & Exponential Function & ~~~~~~~exp & {\large $*$} \\ \hline %--------------------------------------------- 15 \rule[-1.5ex]{0ex}{4ex} & Power Function (Base 2) & ~~~~~~~exp2 & {\large $*$} \\ \hline %--------------------------------------------- 16 \rule[-1.5ex]{0ex}{4ex} & Power Function (Base 10) & ~~~~~~~exp10 & {\large $*$} \\ \hline %--------------------------------------------- 17 \rule[-1.5ex]{0ex}{4ex} & Natural Logarithm (Base $e$) & ~~~~~~~ln & {\large $*$} \\ \hline %--------------------------------------------- 18 \rule[-1.5ex]{0ex}{4ex} & Logarithm (Base 2) & ~~~~~~~log2 & {\large $*$} \\ \hline %--------------------------------------------- 19 \rule[-1.5ex]{0ex}{4ex} & Logarithm (Base 10) & ~~~~~~~log10 & {\large $*$} \\ \hline %--------------------------------------------- 20 \rule[-1.5ex]{0ex}{4ex} & Sine & ~~~~~~~sin & {\large $*$} \\ \hline %--------------------------------------------- 21 \rule[-1.5ex]{0ex}{4ex} & Hyperbolic Sine & ~~~~~~~sinh & {\large $*$} \\ \hline %--------------------------------------------- 22 \rule[-1.5ex]{0ex}{4ex} & Square & ~~~~~~~sqr & {\large $*$} \\ \hline %--------------------------------------------- 23 \rule[-1.5ex]{0ex}{4ex} & Square Root & ~~~~~~~sqrt & {\large $*$} \\ \hline %--------------------------------------------- 24 \rule[-1.5ex]{0ex}{4ex} & Tangent & ~~~~~~~tan & {\large $*$} \\ \hline %--------------------------------------------- 25 \rule[-1.5ex]{0ex}{4ex} & Hyperbolic Tangent & ~~~~~~~tanh & {\large $*$} \\ \hline %--------------------------------------------- \end{tabular}\\[1.5ex] % {\normalsize Table 4:~ \parbox[t]{0.7\textwidth}{Mathematical Standard Functions ($*$ includes the types \mbox{\sl integer, real, complex, interval,\,} and {\sl cinterval})}} \end{center} \vfill Besides the mathematical standard functions, PASCAL--XSC provides the necessary type transfer functions {\sl intval, inf, sup, compl, re\/}, and {\sl im\/} for conversion between the numerical data types (for scalar and array types). \clearpage % % \subsection{The General Operator Concept} % By a simple example of interval addition, the advantages of a general operator concept are demonstrated. In the absence of userdefined operators, there are two ways to implement the addition of two intervals, the latter being declared by \begin{quote} {\bf type} interval = {\bf record} inf,sup: real; \end{quote} One can use a procedure declaration % \begin{quote} \setlength{\tabcolsep}{1pt} {\bf procedure} intadd(a,b: interval; {\bf var} c: interval); \\[0.5ex] {\bf begin} \\[0.5ex] \begin{tabular}{lllll} \ptab c$.$inf & := & a$.$inf & $+ \! <$ & b$.$inf; \\[0.5ex] \ptab c$.$sup & := & a$.$sup & $+ \! >$ & b$.$sup \end{tabular} \\[0.5ex] {\bf end}; \end{quote} \vspace{-1\abovedisplayskip} \[ \begin{array}{|c|c|} \hline \trs\mbox{mathematical notation} & \mbox{corresponding program statement}\\ \hline % z := a+b+c+d & \begin{array}{l} \mbox{intadd(a,b,z);}\rule{0em}{3ex} \\ \mbox{intadd(z,c,z);} \\ \mbox{intadd(z,d,z);}\rule[-1.5ex]{0em}{1ex} \\ \end{array} \\ % \hline \end{array} \] % or a function declaration (only possible in PASCAL--XSC, not in standard PASCAL) % \begin{quote} \setlength{\tabcolsep}{1pt} {\bf function} intadd(a,b: interval): interval; \\[0.5ex] {\bf begin} \\[0.5ex] \begin{tabular}{lllll} \ptab intadd$.$inf & := & a$.$inf & $+ \! <$ & b$.$inf; \\[0.5ex] \ptab intadd$.$sup & := & a$.$sup & $+ \! >$ & b$.$sup \end{tabular} \\[0.5ex] {\bf end}; \end{quote} \vspace{-1\abovedisplayskip} \[ \begin{array}{|c|c|} \hline \trs\mbox{mathematical notation} & \mbox{corresponding program statement}\\ \hline % \trs z := a+b+c+d & \mbox{z := intadd(intadd(intadd(a,b),c),d);} \\ % \hline \end{array} \] % In both cases the description of the mathematical formulas looks rather complicated. By comparison, if one implements an operator in PASCAL--XSC % \begin{quote} \setlength{\tabcolsep}{1pt} {\bf operator} + (a,b: interval) intadd: interval; \\[0.5ex] {\bf begin} \\[0.5ex] \begin{tabular}{lllll} \ptab intadd$.$inf & := & a$.$inf & $+ \! <$ & b$.$inf; \\[0.5ex] \ptab intadd$.$sup & := & a$.$sup & $+ \! >$ & b$.$sup \end{tabular} \\[0.5ex] {\bf end}; \end{quote} \vspace{-1\abovedisplayskip} \[ \begin{array}{|c|c|} \hline \trs\mbox{mathematical notation} & \mbox{corresponding program statement}\\ \hline % \trs z := a+b+c+d & \mbox{z := a + b + c + d;} \\ % \hline \end{array} \] % then a multiple addition of intervals is described in the traditional mathematical notation. Besides the possibility of overloading operator symbols, you are allowed to use named operators. Such operators must be preceded by a priority declaration. There exist four different levels of priority, each represented by its own symbol: % \begin{quote} \begin{tabular}{rlcrl} \quad $\bullet$ & monadic & : & $\uparrow$ & \quad\quad level 3 (highest priority) \\ \quad $\bullet$ & multiplicative & : & $ * $ & \quad\quad level 2 \\ \quad $\bullet$ & additive & : & + & \quad\quad level 1 \\ \quad $\bullet$ & relational & : & = & \quad\quad level 0 \\ \end{tabular} \end{quote} % For example, an operator for the calculation of the binomial coefficient ${n\choose k}$ can be defined in the following manner % \begin{quote} {\bf priority} choose = $*$; \ptab \{priority declaration\} \\[1ex] {\bf operator} choose (n,k: integer) binomial: integer; \\[0.5ex] {\bf var} i,r : integer; \\[0.5ex] {\bf begin} \\[0.5ex] \ptab {\bf if} k $>$ n {\bf div} 2 {\bf then} k := n$-$k; \\[0.5ex] \ptab r := 1; \\[0.5ex] \ptab {\bf for} i := 1 {\bf to} k {\bf do} \\[0.5ex] \ptab\ptab r := r $*$ (n $-$ i + 1) {\bf div} i; \\[0.5ex] \ptab binomial := r; \\[0.5ex] {\bf end}; \end{quote} \vspace{-1\abovedisplayskip} \[ \begin{array}{|c|c|} \hline \trs\mbox{mathematical notation} & \mbox{corresponding program statement}\\ \hline % \trs c := {n \choose k} & \mbox{c := n choose k } \\ % \hline \end{array} \] % The operator concept realized in PASCAL--XSC offers the possibilities of % \begin{itemize} \itemsep0em \item defining an arbitrary number of operators \item overloading operator symbols or operator names arbitrary many times \item implementing recursively defined operators \end{itemize} % The identification of the suitable operator depends on both the number and the type of the operands according to the following {\em weighting\,}-rule: % \begin{quote} \em If the actual list of parameters matches the formal list of para\-meters of two different operators, then the one which is chosen has the first ``better matching'' parameter. ``Better matching'' means that the types of the operands must be consistent and not only conforming. \end{quote} % \pagebreak% % \noindent {\bf Example:} \begin{quote} {\bf operator} +$*$ (a: integer; b: real) irres: real; \\[1.0ex] \ptab $\vdots$ \\[1.0ex] {\bf operator} +$*$ (a: real; b: integer) rires: real; \\[1.0ex] \ptab $\vdots$ \\[1.0ex] {\bf var} \begin{tabular}[t]{lcl} x & : & integer; \\ y, z & : & real; \end{tabular} \\[1.0ex] \ptab \ptab $\vdots$ \\[1.0ex] \ptab z := x +$*$ y; $\:\: \Longrightarrow \:\:$ 1. operator \\[0.5ex] \ptab z := y $+*$ x; $\:\: \Longrightarrow \:\:$ 2. operator \\[0.5ex] \ptab z := x $+*$ x; $\:\: \Longrightarrow \:\:$ 1. operator \\[0.5ex] \ptab z := y $+*$ y; $\:\: \Longrightarrow \:\:$ impossible ! \end{quote} Also, PASCAL--XSC offers the possibility to overload the assignment operator :=. Due to this, the mathematical notation may also be used for assignments: \begin{flushleft} {\bf Example:} \begin{quote} {\bf var} \\[0.5ex] \LL c : complex; \\[0.5ex] \LL r : real; \\[1ex] \LL $\vdots$ \\[1.0ex] {\bf operator} := ({\bf var} c: complex; r: real); \\[0.5ex] \LL {\bf begin}\\[0.5ex] \LL\LL c.re := r;\\[0.5ex] \LL\LL c.im := 0;\\[0.5ex] \LL {\bf end};\\[1ex] $\vdots$ \\[1.0ex] \LL r := 1.5;\\[0.5ex] \LL c := r; ~\{complex number with real part 1.5 and imaginary part 0\} \end{quote} \end{flushleft} % % Neues Kapitel % ============= % \subsection{Overloading of Subroutines} % Standard PASCAL provides the mathematical standard functions \begin{quote} {\sl sin, cos, arctan, exp, ln, sqr}, and {\sl sqrt} \end{quote} for numbers of type {\sl real\,} only. In order to implement the sine function for interval arguments, a function symbol like {\sl isin($\ldots$)} must be used, because the redefining of the standard function name {\sl sin\,} is not allowed in standard PASCAL. By contrast, PASCAL--XSC allows overloading of function and procedure names, whereby a generic symbol concept is introduced into the language. So the symbols \begin{quote} {\sl sin, cos, arctan, exp, ln, sqr}, and {\sl sqrt} \end{quote} can be used not only for numbers of type {\sl real}, but also for intervals, complex numbers, and other mathematical spaces. To distinguish between overloaded functions or procedures with the same name, the number, type, and weighting of their arguments are used, similar to the method for operators. The type of the result, however, is {\em not\,} used. \begin{flushleft} {\bf Example:} \begin{quote} {\bf procedure} rotate ({\bf var} a,b: real); \\[1.0ex] {\bf procedure} rotate ({\bf var} a,b,c: complex); \\[1.0ex] {\bf procedure} rotate ({\bf var} a,b,c: interval); \end{quote} \end{flushleft} The overloading concept also applies to the standard procedures {\sl read\/} and {\sl write\/} in a slightly modified way. The first parameter of a new declared input/output procedure must be a {\bf var}-parameter of file type and the second parameter represents the quantity that is to be input or output. All following parameters are interpreted as format specifications. \begin{flushleft} {\bf Example:} \begin{quote} {\bf procedure} write ({\bf var} f: text; c: complex; w: integer);\\ {\bf begin}\\ \LL write (f, '(', c.re : w, ',', c.im : w, ')');\\ {\bf end} \end{quote} \end{flushleft} Calling an overloaded input/output procedure the file parameter may be omitted corresponding to a call with the standard files {\sl input\/} or {\sl output\/}. The format parameters must be introduced and seperated by colons. Moreover, several input or output statements can be combined to a single statement as in standard PASCAL. \begin{flushleft} {\bf Example:} \begin{quote} {\bf var} \\ \LL r: real;\\ \LL c: complex;\\ \LL $\vdots$ \\ write (r : 10, c : 5, r/5); \end{quote} \end{flushleft} % % Neues Kapitel % ============= % \subsection{The Module Concept} % \label{sec:psc4} Standard PASCAL basically assumes that a program consists of a single program text which must be prepared completely before it can be compiled and executed. In many cases, it is more convenient to prepare a program in several parts, called modules, which can then be developed and compiled independently of each other. Moreover, several other programs may use the components of a module without their being copied into the source code and recompiled. For this purpose, a module concept has been introduced in PASCAL--XSC. This new concept offers the possibilities of % \begin{itemize} \itemsep0em \item modular programming \item syntax check and semantic analysis beyond the bounds of modules \item implementation of arithmetic packages as standard modules \end{itemize} % Three new keywords have been added to the language: % \begin{quote} \setlength{\tabcolsep}{0cm} \begin{tabular}{lll} {\bf module}~~~~ & : &~~~~starts a new module \\[1.0ex] {\bf global} & : &~~~~indicates items to be passed to the outside \\[1.0ex] {\bf use} & : &~~~~indicates imported modules \end{tabular} \end{quote} % \noindent A module is introduced by the keyword {\bf module} followed by a name and a semicolon. The body is built up quite similarly to that of a normal program with the exception that the word symbol {\bf global} can be used directly in front of the keywords {\bf const}, {\bf type}, {\bf var}, {\bf procedure}, {\bf function}, and {\bf operator} and directly after {\bf use} and the equality sign in type declarations. Thus it is possible to declare anonymous types as well as non-anonymous types. The structure of an anonymous type is not known outside the declar\-ation module and can only be influenced by subroutine calls. If, for example, the internal structure as well as the name of a type is to be made global, then the word symbol {\bf global} must be repeated after the equality sign. By means of the declaration % \begin{quote} {\bf global type} complex = {\bf global record} re, im : real {\bf end;} \end{quote} % the type {\sl complex\,} and its internal structure as a record with components {\sl re\,} and {\sl im\,} is made global. \noindent An anonymous type {\sl complex\,} could be declared by % \begin{quote} {\bf global type} complex = {\bf record} re, im: real {\bf end;} \end{quote} % The user who has imported a module with this anonymous definition cannot refer to the record components, because the structure of the type is hidden inside the module. % \pagebreak% % \noindent A module is built up according to the following pattern: % \begin{quote} {\bf module} m1; \\[0.5ex] {\bf use} $<$\,other modules\,$>$; \\[0.5ex] \ptab $<$\,global and local declarations\,$>$ \\[0.5ex] {\bf begin} \\[0.5ex] \ptab $<$\,initialization of the module\,$>$ \\[0.5ex] {\bf end.} \end{quote} % For importing modules with {\bf use} or {\bf use global} the following transitivity rules hold % \begin{quote} M1 {\bf use} M2 \quad and \quad M2 {\bf use global} M3 $\:\:\Rightarrow\:\:$ M1 {\bf use} M3. \end{quote} % but % \begin{quote} M1 {\bf use} M2 \quad and \quad M2 {\bf use} M3 \hspace{7ex} $\:\:\not\Rightarrow\:\:$ M1 {\bf use} M3, \end{quote} % \noindent {\bf Example:} Let a module hierarchy be built up by \[ \begin{array}{c} \setlength{\unitlength}{1.3em} \begin{picture}(19,7) % % beschriftete Kaestchen % \put( 0.0,0){\framebox(1,1){X}} \put( 4.0,0){\framebox(1,1){Y}} \put(10.5,0){\framebox(5,1){\small STANDARDS}} \put( 2.0,3){\framebox(1,1){A}} \put( 9.0,3){\framebox(1,1){B}} \put(16.0,3){\framebox(1,1){C}} \put( 6.0,6){\framebox(7,1){\small main program}} % % Verbindungslinien von unten nach oben % \put( 0.5,1.0){\line( 1,1){2}} \put( 4.5,1.0){\line(-1,1){2}} \put(12.5,1.0){\line(-3,2){3}} \put(13.5,1.0){\line( 3,2){3}} \put( 2.5,4.0){\line( 2,1){4}} \put( 9.5,4.0){\line( 0,1){2}} \put(16.5,4.0){\line(-2,1){4}} \end{picture} \end{array} \] All global objects of the modules A, B, and C are visible in the main program unit, but there is no access to the global objects of X, Y and STANDARDS. There are two possibilities to make them visible in the main program, too: % \begin{enumerate} \itemsep0em \item to write \begin{quote} {\bf use} X, Y, STANDARDS \end{quote} in the main program \item to write \begin{quote} {\bf use global} X, Y \end{quote} in module A and \begin{quote} {\bf use global} STANDARDS \end{quote} in module B or C. \end{enumerate} \pagebreak % % Neues Kapitel % ============= % \subsection{Dynamic Arrays} % In standard PASCAL there is no way to declare dynamic types or variables. For instance, program packages with vector and matrix operations can be implemented with only fixed (maximum) dimension. For this reason, only a part of the allocated memory is used if the user wants to solve problems with lower dimension only. The concept of dynamic arrays removes this limitation. In particular, the new concept can be described by the following characteristics: % \begin{itemize} \itemsep0em \item Dynamics insides of procedures and functions \item Automatic allocation and deallocation of local dynamic variables \item Economical employment of storage space \item Row access and column access to dynamic arrays \item Compatibility of static and dynamic arrays \end{itemize} % Dynamic arrays must be marked with the word symbol {\bf dynamic}. The great disadvantage of the {\sl conformant array\,} schemes available in standard PASCAL is that they can only be used for parameters and not for variables or function results. There is no question of this use being fully dynamic. In PASCAL--XSC, dynamic and static arrays can be used in the same manner. At the moment, dynamic arrays may not be components of other data structures. The syntactical meaning of this is that the word symbol {\bf dynamic} may only be used directly following the equality sign in a type definition or directly following the colon in a variable declaration. For instance, dynamic arrays may not be record components. \noindent A two-dimensional array type can be declared in the following manner: % \begin{quote} {\bf type} matrix = {\bf dynamic array}[$*$,$*$] {\bf of} real; \end{quote} % It is also possible to define different dynamic types with corresponding syntactical structures. For example, it might be useful in some situations to identify the coefficients of a polynomial with the components of a vector or vice versa. Since PASCAL is strictly a type-oriented language, such structurally equivalent arrays may only be combined if their types have been previously adapted. The following example shows the definition of a polynomial and of a vector type (note that the type adaptation functions {\sl polynomial($\ldots$)\,} and {\sl vector($\ldots$)\,} are defined implicitly): % \begin{quote} {\bf type} vector = {\bf dynamic array}[$*$] {\bf of} real; \\[1.0ex] {\bf type} polynomial = {\bf dynamic array}[$*$] {\bf of} real; \\[1.0ex] {\bf operator} + (a,b: vector) res: vector[lbound(a)..ubound(a)]; \\[1.0ex] \ptab $\vdots$ \\[1.0ex] {\bf var} \begin{tabular}[t]{lcl} v & : & vector[1..n]; \\ p & : & polynomial[0..n-1]; \end{tabular} \\[1.0ex] \ptab $\vdots$ \\[1.0ex] \ptab v := vector(p); \\[0.5ex] \ptab p := polynomial(v); \\[0.5ex] \ptab v := v + v; \\[0.5ex] \ptab v := vector(p) + v; \{ but not v := p + v; \} \end{quote} % Access to the lower and upper index limits is made possible by the new standard functions {\sl lbound($\ldots$)\,} and {\sl ubound($\ldots$)}, which are available with an optional argument for the index field of the designated dynamic variable. Employing these functions, the operator mentioned above can be written as % \begin{quote} {\bf operator} + (a,b: vector) res: vector[lbound(a)..ubound(a)]; \\[1.0ex] {\bf var} i : integer; \\[1.0ex] {\bf begin} \\[1.0ex] \ptab {\bf for} i := lbound(a) {\bf to} ubound(a) {\bf do} \\[1.0ex] \ptab \ptab res[i] := a[i] + b[lbound(b) + i -- lbound(a)] \\[1.0ex] {\bf end;} \end{quote} % Introduction of dynamic types requires an extension of the compatibility prerequisites. As in standard PASCAL, two array types are not compatible unless they are of the same type. Consequently, a dynamic array type is not compatible with a static type. In PASCAL--XSC value assignments are always possible in the cases listed in Table 5. \begin{center} \footnotesize \begin{tabular}{|c|c|c|} \hline \trs Type of Left Side & Type of Right Side & Assignment Permitted \\[0.8ex] \hline \trs anonymous dynamic & arbitrary {\sl array\,} type & if structurally equivalent\\[0.8ex] \trs known dynamic & known dynamic & if types are the same\\[0.8ex] \trs anonymous static & arbitrary {\sl array\,} type & if structurally equivalent\\[0.8ex] \trs known static & known static & if types are the same\\[0.8ex] \hline \end{tabular}\\[1.5ex] {\normalsize Table 5:~ Assignment Compatibilities} \end{center} % In the remaining cases, an assignment is possible only for equivalent qualification of the right side (see \cite{pxscbuch} or \cite{pxscbook} for details). In addition to access to each component variable, PASCAL--XSC offers the possibility of access to entire subarrays. If a component variable contains an $*$ instead of an index expression, it refers to the subarray with the entire index range in the corresponding dimension, e.\ g.\ via {\sl m[$*$,\,j]\/} the {\sl j\/}-th column of a two-dimensional array {\sl m\/} is accessed. This example demonstrates access to rows or columns of dynamic arrays: % \pagebreak % \begin{quote} {\bf type} vector = {\bf dynamic array}[$*$] {\bf of} real; \\[0.5ex] {\bf type} matrix = {\bf dynamic array}[$*$] {\bf of} vector; \\[0.5ex] \ptab $\vdots$ \\[1.0ex] {\bf var} \begin{tabular}[t]{lcl} v & : & vector[1..n]; \\ m & : & matrix[1..n,1..n]; \end{tabular} \\[0.5ex] \ptab $\vdots$ \\[0.5ex] \ptab v := m[i]; \\[0.5ex] \ptab m[i] := vector(m[$*$,~j]); \end{quote} % In the first assignment it is not necessary to use a type adaptation function, since both the left-hand and the right-hand side are of {\em known dynamic\/} type. A different case is demonstrated in the second assignment. The left-hand side is of {\em known dynamic\/} type, but the right-hand side is of {\em anonymous dynamic\/} type, so it is necessary to use the intrinsic adaptation function {\sl vector($\ldots$)}. A PASCAL--XSC program which uses dynamic arrays should be built up according to the following scheme: % \begin{quote} {\bf program} dynprog (input,output); \\[0.7ex] {\bf type} \\[0.7ex] \ptab vector = {\bf dynamic array}[$*$] {\bf of} real; \\[0.7ex] \ptab $<$\,different dynamic declarations\,$>$ \\[0.7ex] {\bf var} n : integer; \\[0.7ex] \{ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \} \\[0.7ex] {\bf procedure} main (dim: integer); \\[0.7ex] {\bf var} a,b,c : vector[1..dim]; \\[0.7ex] \ptab $\vdots$ \\[0.7ex] {\bf begin} \\[0.7ex] \ptab $<$\,I/O depending on the value of dim\,$>$ \\[0.7ex] \ptab \ptab $\vdots$ \\[0.7ex] \ptab c := a + b; \\[0.7ex] \ptab \ptab $\vdots$ \\[0.7ex] {\bf end;} \\[0.7ex] \{ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \} \\[0.7ex] {\bf begin} \{main program\} \\[0.7ex] \ptab read(n); \\[0.7ex] \ptab main(n); \\[0.7ex] {\bf end.} \{main program\} \end{quote} % It is necessary to frame only the original main program by a procedure (here: {\sl main\/}), which is refered to with the dimension of the dynamic arrays as a transfer parameter. %